package com.huluobo.a2109mouthdemo.mine;


import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.huluobo.a2109mouthdemo.R;
import com.huluobo.a2109mouthdemo.base.BaseFragment;
import com.huluobo.a2109mouthdemo.login.LoginActivity;
import com.hyphenate.chat.EMClient;

public class MineFragment extends BaseFragment<MineContract.View, MinePresenter> implements MineContract.View {

    private Button logout_btn;

    @Override
    protected int bindLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void initData() {
        presenter = new MinePresenter();
    }

    @Override
    protected void initView() {
        logout_btn = findViewById(R.id.mine_logout);
        logout_btn.setOnClickListener(v -> presenter.logout());

        String username = String.format(getString(R.string.logout), EMClient.getInstance().getCurrentUser());
        logout_btn.setText(username);
    }

    @Override
    public void onLogoutSuccess() {
        Intent intent = new Intent(getContext(), LoginActivity.class);
        startActivity(intent);
        getActivity().finish();
    }

    @Override
    public void onLogoutFailed(String error) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getContext(), "退出失败:" + error, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onStartLogout() {

    }
}